import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import pinia from '@/stores/pinia'
import './assets/global.css'
import '@/utils/request'
import { permission } from '@/directives/permission'
import { io } from "socket.io-client" // 引入socket.io-client模块
import {getToken} from "@/utils/token"

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(router)
app.use(ElementPlus)
app.use(pinia)
app.directive('perm', permission)
app.mount('#app')

// // 创建socket.io实例
// const socket = io(import.meta.env.VITE_SOCKET_URL, { withCredentials: true })
// // 监听连接事件
// socket.on('connect', () => {
//     console.log('已连接到服务器');
// });
// // 监听消息事件
// socket.on('renewToken', (data) => {
//     console.log('收到服务器消息:', data);
//     if(data.status){
//         let res = confirm("即将过期，是否续期token")
//         if(res){
//             let token = getToken()
//             socket.emit("needRenewToken",{
//                 msg:"续期token",
//                 needRenewtoken:1,
//                 token
//             })
//         }else{
//             socket.emit("needRenewToken",{
//                 msg:"不续期token",
//                 needRenewToken:0
//             })
//         }
//     }
// });
